package com.example.demo.DBServer.thisDatabase.dao;

import com.example.demo.entity.RelatedExecuteInformationEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RelatedExecuteInformationDao {
    /**
     * 新增一条关联信息
     */
    @Insert({"<script>"
                + "insert into t_related_execute_information"
                + "(execute_information_id, parent_related_id, table_name, "
                + "parent_column, current_column, execute_type, "
                + "archive_type, backup_deal_type) "
                + "values"
                + "(#{info.executeInformationId}, #{info.parentRelatedId}, #{info.tableName}, "
                + " #{info.parentColumn}, #{info.currentColumn}, #{info.executeType}, "
                + " #{info.archiveType},#{info.backupDealType})"
            + "</script>"
    })
    @Options(useGeneratedKeys = true, keyProperty = "info.id", keyColumn = "id")
    Integer saveRelatedExecuteInformation(@Param("info")RelatedExecuteInformationEntity relatedExecuteInformation);
    /**
     * 批量插入关联处理信息
     */
    @Insert({"<script>"
            + "INSERT INTO `t_related_execute_information` "
            + "(execute_information_id, parent_related_id, table_name, "
            + " parent_column, current_column, execute_type, "
            + " archive_type, backup_deal_type) "
            + "VALUES "
            + "<foreach collection='list' item='item' index='index' separator=','>"
            + "(#{info.executeInformationId}, #{info.parentRelatedId}, #{info.tableName}, "
            + " #{info.parentColumn}, #{info.currentColumn}, #{info.executeType}, "
            + " #{info.archiveType}, #{info.backupDealType})"
            + "</foreach>"
            + "</script>"
    })
    Integer batchSaveRelatedExecuteInformation(List<RelatedExecuteInformationEntity> list);
    /**
     * 根据id查询一个关联信息
     */
    @Select(value = {"select * from t_related_execute_information where id = #{id} "})
    @Results(id = "relatedExecuteMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "execute_information_id", property = "executeInformationId"),
            @Result(column = "parent_related_id", property = "parentRelatedId"),
            @Result(column = "table_name", property = "tableName"),
            @Result(column = "parent_column", property = "parentColumn"),
            @Result(column = "current_column", property = "currentColumn"),
            @Result(column = "execute_type", property = "executeType"),
            @Result(column = "archive_type", property = "archiveType"),
            @Result(column = "backup_deal_type", property = "backupDealType")
    })
    RelatedExecuteInformationEntity findOneById(Long id);
    /**
     * 根据执行信息id查询
     */
    @Select(value = {"select * from t_related_execute_information where execute_information_id = #{executeInformationId} "})
    @ResultMap("relatedExecuteMap")
    List<RelatedExecuteInformationEntity> findAllByExecuteInformationId(Long executeInformationId);
}
